package net.jueb.juebCore.net.handler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import net.jueb.juebCore.net.codec.AppMsgDecoder;
import net.jueb.juebCore.net.codec.AppMsgEncoder;
import net.jueb.juebCore.net.message.AppMessage;
import net.jueb.util4j.net.JConnectionIdleListener;
import net.jueb.util4j.net.nettyImpl.handler.listenerHandler.adapter.IdleListenerHandlerAdapter;

public class InitalizerAppMsgPublicHandler extends ChannelInitializer<SocketChannel> {

	private JConnectionIdleListener<AppMessage> listener;

	public InitalizerAppMsgPublicHandler(JConnectionIdleListener<AppMessage> listener) {
		this.listener = listener;
	}

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline p = ch.pipeline();
		p.addLast(new AppMsgDecoder(true));
		p.addLast(new AppMsgEncoder(true));
		p.addLast(new IdleListenerHandlerAdapter<AppMessage>(listener));
	}
}